var dicefun = {
	init:function(){
		var container = document.getElementById('dicebox');
		$('.redpacket').remove();
		var arr = this.randomFun();
		var a = arr.join(',');

		for (var i = 0 ; i<6;i++) {
			container.appendChild(this.createDice(arr[i]+1,i));
		}

		var s_name = localStorage.getItem("s_name");
		var s_number = localStorage.getItem("s_number");
		// var select_sex = $("#user_sex").val();
            $.ajax({
                url : "http://120.79.48.184/zkw_blog/addBobing",
				// url : "http://localhost/zkw_blog/addBobing",
				type : "POST",
                data : {
					s_number:s_number,
					s_name:s_name,
					arr1:a
                },
                dataType : "json",
                success : function (data) {
                	if (data.currentDay==true){
                		alert("你今天已经博过了哦,明天再来把");
					}else {
						setTimeout(function () {
						    console.log(data.noResult);
							if(data.noResult==true){
                                alert("很遗憾你" + data.result+"呢");
                            }else{
                                alert("恭喜:" + s_name + ",你博到了：" + data.result);
                            }
						}, 0 * 1000);
					}
                },
                error : function (data) {
                    alert("请求失败");
                }
            })



	},
	randomFun:function(){
		var arr = [];
		for (var i = 0 ; i<6;i++ ) {
			arr.push(Math.floor(Math.random()*6));
		}
		return arr;
	},
	createDice:function(num,i){
		var image = document.createElement('img');
   		  	image.setAttribute("class","redpacket");
   		  	image.id = "redpacket" + i;
    	  	image.src = 'activity/img/' + num +'.jpg';
    	  	return image;
	},
}
